package com.fdb.efp.nls.service.impl;

import com.fdb.basic.framework.core.base.FrameworkService;
import com.fdb.efp.nls.service.dao.RscTaskLoanDao;
import com.fdb.efp.nls.service.domain.RscTaskLoan;
import com.fdb.efp.nls.service.facade.RscTaskLoanService;
import com.fdb.efp.nls.service.vo.RscTaskLoanVO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Objects;

/**
 * <p>ServiceImpl: 风险分类台账				<p>
 * @author luzy
 * @date 2019-09-07
 */
@Service("rscTaskLoanService")
public class RscTaskLoanServiceImpl implements RscTaskLoanService, FrameworkService {
	
	private static Logger logger = LoggerFactory.getLogger(RscTaskLoanServiceImpl.class);

	@Autowired
	private RscTaskLoanDao rscTaskLoanDao;
	
	/**
	 * 新增操作
	 */
	public int insertRscTaskLoan(RscTaskLoanVO inRscTaskLoanVo) {
		logger.debug("当前新增数据为:"+ inRscTaskLoanVo.toString());
		int num = 0;
		try {
			RscTaskLoan rscTaskLoan = new RscTaskLoan();
			beanCopy(inRscTaskLoanVo, rscTaskLoan);
			num = rscTaskLoanDao.insertRscTaskLoan(rscTaskLoan);
		} catch (Exception e) {
			logger.error("新增数据发生异常!", e);
			num = -1;
		}
		logger.debug("当前新增数据条数为:"+ num);
		return num;
	}

	/**
	 * 删除操作
	 */
	public int deleteByPk(RscTaskLoanVO inRscTaskLoanVo) {
		logger.debug("当前删除数据条件为:"+ inRscTaskLoanVo);
		int num = 0;
		try {
			RscTaskLoan rscTaskLoan = new RscTaskLoan();
			beanCopy(inRscTaskLoanVo, rscTaskLoan);
			num = rscTaskLoanDao.deleteByPk(rscTaskLoan);
		} catch (Exception e) {
			logger.error("删除数据发生异常!", e);
			num = -1;
		}
		logger.debug("根据条件:"+ inRscTaskLoanVo +"删除的数据条数为"+ num);
		return num;
	}


	/**
	 * 更新操作
	 */
	public int updateByPk(RscTaskLoanVO inRscTaskLoanVo) {
		logger.debug("当前修改数据为:"+ inRscTaskLoanVo.toString());
		int num = 0;
		try {
			RscTaskLoan rscTaskLoan = new RscTaskLoan();
			beanCopy(inRscTaskLoanVo, rscTaskLoan);
			num = rscTaskLoanDao.updateByPk(rscTaskLoan);
		} catch (Exception e) {
			logger.error("修改数据发生异常!", e);
			num = -1;
		}
		logger.debug("根据条件:"+ inRscTaskLoanVo +"修改的数据条数为"+ num);
		return num;
	}
	
	/**
	 * 查询操作
	 */
	public RscTaskLoanVO queryByPk(RscTaskLoanVO inRscTaskLoanVo) {
		
		logger.debug("当前查询参数信息为:"+ inRscTaskLoanVo);
		try {
			RscTaskLoan queryRscTaskLoan = new RscTaskLoan();
			beanCopy(inRscTaskLoanVo, queryRscTaskLoan);
			RscTaskLoan queryRslRscTaskLoan = rscTaskLoanDao.queryByPk(queryRscTaskLoan);
			if (Objects.nonNull(queryRslRscTaskLoan)) {
				RscTaskLoanVO outRscTaskLoanVo = beanCopy(queryRslRscTaskLoan, new RscTaskLoanVO());
				logger.debug("当前查询结果为:"+ outRscTaskLoanVo.toString());
				return outRscTaskLoanVo;
			} else {
				logger.debug("当前查询结果为空!");
			}
		} catch (Exception e) {
			logger.error("查询数据发生异常!", e);
		}
		return null;
	}


	/**
	 * 查询用户权限数据
	 */
	@SuppressWarnings("unchecked")
	public List<RscTaskLoanVO> queryAllOwner(RscTaskLoanVO rscTaskLoanVo) {

		logger.debug("当前查询本人所属数据信息的参数信息为:");
		List<RscTaskLoanVO> list = null;
		try {
			List<RscTaskLoan> rscTaskLoans = rscTaskLoanDao.queryAllOwnerByPage(rscTaskLoanVo);
			logger.debug("当前查询本人所属数据信息的结果集数量为:"+ rscTaskLoans.size());
			pageSet(rscTaskLoans, rscTaskLoanVo);
			list = (List<RscTaskLoanVO>) beansCopy(rscTaskLoans, RscTaskLoanVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}
		
		return list;
	
	}


	/**
	 * 查询当前机构权限数据
	 */
	@SuppressWarnings("unchecked")
	public List<RscTaskLoanVO> queryAllCurrOrg(RscTaskLoanVO rscTaskLoanVo) {

		logger.debug("当前查询本人所属机构数据信息的参数信息为:");
		List<RscTaskLoan> rscTaskLoans = rscTaskLoanDao.queryAllCurrOrgByPage(rscTaskLoanVo);
		logger.debug("当前查询本人所属机构数据信息的结果集数量为:"+rscTaskLoans.size());
		List<RscTaskLoanVO> list = null;
		try {
			pageSet(rscTaskLoans, rscTaskLoanVo);
			list = (List<RscTaskLoanVO>) beansCopy(rscTaskLoans, RscTaskLoanVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}
		
		return list;
	
	}


	/**
	 * 查询当前机构及下属机构权限数据
	 */
	@SuppressWarnings("unchecked")
	public List<RscTaskLoanVO> queryAllCurrDownOrg(RscTaskLoanVO rscTaskLoanVo) {

		logger.debug("当前查询本人所属机构及以下数据信息的参数信息为:");
		List<RscTaskLoan> rscTaskLoans = rscTaskLoanDao.queryAllCurrDownOrgByPage(rscTaskLoanVo);
		logger.debug("当前查询本人所属机构及以下数据信息的结果集数量为:"+ rscTaskLoans.size());
		List<RscTaskLoanVO> list = null;
		try {
			pageSet(rscTaskLoans, rscTaskLoanVo);
			list = (List<RscTaskLoanVO>) beansCopy(rscTaskLoans, RscTaskLoanVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}
		
		return list;
	
	}

	/**
	 * 查询当前产品种类
	 */
	@SuppressWarnings("unchecked")
	public List<RscTaskLoanVO> queryAllCurrOwnerPrd(RscTaskLoanVO rscTaskLoanVo) {

		logger.debug("当前当前产品种类数据信息的参数信息为:");
		List<RscTaskLoan> rscTaskLoans = rscTaskLoanDao.queryAllCurrOwnerPrdByPage(rscTaskLoanVo);
		logger.debug("当前当前产品种类下数据信息的结果集数量为:"+ rscTaskLoans.size());
		List<RscTaskLoanVO> list = null;
		try {
			pageSet(rscTaskLoans, rscTaskLoanVo);
			list = (List<RscTaskLoanVO>) beansCopy(rscTaskLoans, RscTaskLoanVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}
		return list;
	}

	@Override
	public RscTaskLoanVO queryByContNo(RscTaskLoanVO queryRscTaskLoan) {
		logger.debug("当前查询参数信息为:"+ queryRscTaskLoan);
		try {
			RscTaskLoan RscTaskLoan = new RscTaskLoan();
			beanCopy(queryRscTaskLoan, RscTaskLoan);
			RscTaskLoan queryRslRscTaskLoan = rscTaskLoanDao.queryByContNo(RscTaskLoan);
			if (Objects.nonNull(queryRslRscTaskLoan)) {
				RscTaskLoanVO outRscTaskLoanVo = beanCopy(queryRslRscTaskLoan, new RscTaskLoanVO());
				logger.debug("当前查询结果为:"+ outRscTaskLoanVo.toString());
				return outRscTaskLoanVo;
			} else {
				logger.debug("当前查询结果为空!");
			}
		} catch (Exception e) {
			logger.error("查询数据发生异常!", e);
		}
		return null;
	}

	@Override
	public int updateByBillNo(RscTaskLoanVO queryRscTaskLoan) {
		logger.debug("当前修改数据为:"+ queryRscTaskLoan.toString());
		int num = 0;
		try {
			RscTaskLoan rscTaskLoan = new RscTaskLoan();
			beanCopy(queryRscTaskLoan, rscTaskLoan);
			num = rscTaskLoanDao.updateByBillNo(rscTaskLoan);
		} catch (Exception e) {
			logger.error("修改数据发生异常!", e);
			num = -1;
		}
		logger.debug("根据条件:"+ queryRscTaskLoan +"修改的数据条数为"+ num);
		return num;
	}

	@Override
	public RscTaskLoanVO queryByBillNo(RscTaskLoanVO queryRscTaskLoan) {
		
		logger.debug("当前查询参数信息为:"+ queryRscTaskLoan);
		try {
			RscTaskLoan rscTaskLoan = new RscTaskLoan();
			beanCopy(queryRscTaskLoan, rscTaskLoan);
			RscTaskLoan queryRslRscTaskLoan = rscTaskLoanDao.queryByBillNo(rscTaskLoan);
			if (Objects.nonNull(queryRslRscTaskLoan)) {
				RscTaskLoanVO outRscTaskLoanVo = beanCopy(queryRslRscTaskLoan, new RscTaskLoanVO());
				logger.debug("当前查询结果为:"+ outRscTaskLoanVo.toString());
				return outRscTaskLoanVo;
			} else {
				logger.debug("当前查询结果为空!");
			}
		} catch (Exception e) {
			logger.error("查询数据发生异常!", e);
		}
		return null;
	}
	/**
	 * 导出功能
	 * 查询用户权限数据
	 */
	@SuppressWarnings("unchecked")
	public List<RscTaskLoanVO> querySignAll(RscTaskLoanVO rscTaskLoanVo) {
		logger.debug("当前查询本人所属数据信息的参数信息为:");
		List<RscTaskLoanVO> list = rscTaskLoanDao.querySignAll(rscTaskLoanVo);;
		return list;

	}

	@Override
	public List<RscTaskLoanVO> queryExAllOwner(RscTaskLoanVO rscTaskLoanVo) {

		logger.debug("当前查询本人所属数据信息的参数信息为:");
		List<RscTaskLoanVO> list = null;
		try {
			List<RscTaskLoan> rscTaskLoans = rscTaskLoanDao.queryAllOwner(rscTaskLoanVo);
			logger.debug("当前查询本人所属数据信息的结果集数量为:"+ rscTaskLoans.size());
			pageSet(rscTaskLoans, rscTaskLoanVo);
			list = (List<RscTaskLoanVO>) beansCopy(rscTaskLoans, RscTaskLoanVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}

		return list;

	}


	/**
	 * 查询当前机构权限数据
	 */
	@Override
	public List<RscTaskLoanVO> queryExAllCurrOrg(RscTaskLoanVO rscTaskLoanVo) {

		logger.debug("当前查询本人所属机构数据信息的参数信息为:");
		List<RscTaskLoan> rscTaskLoans = rscTaskLoanDao.queryAllCurrOrg(rscTaskLoanVo);
		logger.debug("当前查询本人所属机构数据信息的结果集数量为:"+rscTaskLoans.size());
		List<RscTaskLoanVO> list = null;
		try {
			pageSet(rscTaskLoans, rscTaskLoanVo);
			list = (List<RscTaskLoanVO>) beansCopy(rscTaskLoans, RscTaskLoanVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}

		return list;

	}


	/**
	 * 查询当前机构及下属机构权限数据
	 */
	@Override
	public List<RscTaskLoanVO> queryExAllCurrDownOrg(RscTaskLoanVO rscTaskLoanVo) {

		logger.debug("当前查询本人所属机构及以下数据信息的参数信息为:");
		List<RscTaskLoan> rscTaskLoans = rscTaskLoanDao.queryAllCurrDownOrg(rscTaskLoanVo);
		logger.debug("当前查询本人所属机构及以下数据信息的结果集数量为:"+ rscTaskLoans.size());
		List<RscTaskLoanVO> list = null;
		try {
			pageSet(rscTaskLoans, rscTaskLoanVo);
			list = (List<RscTaskLoanVO>) beansCopy(rscTaskLoans, RscTaskLoanVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}

		return list;

	}

	/**
	 * 查询当前产品种类
	 */
	@Override
	public List<RscTaskLoanVO> queryExAllCurrOwnerPrd(RscTaskLoanVO rscTaskLoanVo) {

		logger.debug("当前当前产品种类数据信息的参数信息为:");
		List<RscTaskLoan> rscTaskLoans = rscTaskLoanDao.queryAllCurrOwnerPrd(rscTaskLoanVo);
		logger.debug("当前当前产品种类下数据信息的结果集数量为:"+ rscTaskLoans.size());
		List<RscTaskLoanVO> list = null;
		try {
			pageSet(rscTaskLoans, rscTaskLoanVo);
			list = (List<RscTaskLoanVO>) beansCopy(rscTaskLoans, RscTaskLoanVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}
		return list;
	}

	public List<RscTaskLoanVO> queryAllAdjustByPage(RscTaskLoanVO rscTaskLoanVo) {

		logger.debug("当前查询本人所属数据信息的参数信息为:");
		List<RscTaskLoanVO> list = null;
		try {
			List<RscTaskLoan> rscTaskLoans = rscTaskLoanDao.queryAllAdjustByPage(rscTaskLoanVo);
			logger.debug("当前查询本人所属数据信息的结果集数量为:"+ rscTaskLoans.size());
			pageSet(rscTaskLoans, rscTaskLoanVo);
			list = (List<RscTaskLoanVO>) beansCopy(rscTaskLoans, RscTaskLoanVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}

		return list;

	}
	
}
